﻿using NLog.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace KongZhiTaiTest.ThreadAndLockTest
{
    public class LogCollectSet
    {
        private static List<string> ListValue = new List<string>();
        private readonly static object locker = new object();
        private readonly static object locker1 = new object();

        public static void Reload()
        {
            lock (locker)
            {
                Console.WriteLine("====start====重新加载日志集合！！");
                Thread.Sleep(2000);
                ListValue.Clear();
                ListValue.Add("你好");
                ListValue.Add("李焕英");
                Console.WriteLine("====end====加载日志集合完成！");
            }
        }

        public static void ReadSet()
        {
            lock (locker)
            {
                Console.WriteLine("####开始读取集合内容####");
                foreach (var item in ListValue)
                {
                    Console.WriteLine(item);
                    Thread.Sleep(2000);
                }
                Console.WriteLine("####集合读取完毕####");
            }
        }

        public static void Show()
        {
            Thread thread1 = new Thread(ReadSet);
            Thread thread2 = new Thread(Reload);
            thread2.Start();
            thread1.Start();
        }
    }
}
